﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DIST.LR.Library.SL.Controls.Adapter;
using DIST.LR.Library.SL.Controls.Factory;
using C1.Silverlight.FlexGrid;
using System.Collections.ObjectModel;
using DIST.LR.ZHJG.Events;


namespace DIST.LR.ZHJG.Controls.Grid
{
    public partial class ucFlexGrid : UserControl
    { 
        //IFlexGridAdapter _MxAdapter = null;
        public ucFlexGrid()
        {
            InitializeComponent();
            InitFlexGrid1();
            InitFlexGrid2();
        }
        public void TransitVisible(bool isVisible)
        {
            if (isVisible)
            {
                this.FlexGrid1.Visibility = Visibility.Visible;
                this.FlexGrid2.Visibility = Visibility.Collapsed;
            }
            else
            {
                this.FlexGrid1.Visibility = Visibility.Collapsed;
                this.FlexGrid2.Visibility = Visibility.Visible;
            }
 
        }
        public void InitFlexGrid1()
        {
            IFlexGridAdapter _MxAdapter = null;    
            IControlAdapterFactory pFactory = new DIST.LR.Library.SL.Controls.Combination.ControlAdapterFactory();
            this.FlexGrid1.RowHeaders.Rows.Clear();
            this.FlexGrid1.RowHeaders.Columns.Clear();
            this.FlexGrid1.Columns.Clear();
            this.FlexGrid1.Rows.Clear();
            _MxAdapter = pFactory.CreateFlexGridAdapter(this.FlexGrid1);
           
            string sColumnHeader = @"年份，季度，指标，
                                            城区|招拍挂，城区|协议出让，城区|划拨，
                                            萧山区|招拍挂，萧山区|协议出让，萧山区|划拨，
                                            余杭区|招拍挂，余杭区|协议出让，余杭区|划拨，
                                            临安市|招拍挂，临安市|协议出让，临安市|划拨，
                                            桐庐县|招拍挂，桐庐县|协议出让，桐庐县|划拨，
                                            淳安县|招拍挂，淳安县|协议出让，淳安县|划拨，
                                            建德市|招拍挂，建德市|协议出让，建德市|划拨，
                                            富阳市|招拍挂，富阳市|协议出让，富阳市|划拨";
            string sColumnDataBind = @"nf,jd,zb,cq_zpg,cq_xycr,cq_hb,xsq_zpg,xsq_xycr,xsq_hb,yhq_zpg,yhq_xycr,yhq_hb,las_zpg,las_xycr,las_hb,tlx_zpg,tlx_xycr,tlx_hb,chax_zpg,chax_xycr,chax_hb,jds_zpg,jds_xycr,jds_hb,fys_zpg,fys_xycr,fys_hb";
            _MxAdapter.ColumnHeader = sColumnHeader;
            _MxAdapter.ColumnDataBind = sColumnDataBind;
            _MxAdapter.SetColumnHorizontalAlignment(0, System.Windows.HorizontalAlignment.Center);
            _MxAdapter.Style = FlexGridStyle_LR.White;
            _MxAdapter.AutoSelectRow = false;            
            _MxAdapter.SeletionBarkground = new SolidColorBrush(Colors.Orange); 
            this.FlexGrid1.AllowMerging = AllowMerging.All;          
            _MxAdapter.ItemsSource = GetDatasource();
        
        }
        public void InitFlexGrid2()
        {
            IFlexGridAdapter _MxAdapter = null; 
            IControlAdapterFactory pFactory = new DIST.LR.Library.SL.Controls.Combination.ControlAdapterFactory();
            this.FlexGrid2.RowHeaders.Rows.Clear();
            this.FlexGrid2.RowHeaders.Columns.Clear();
            this.FlexGrid2.Columns.Clear();
            this.FlexGrid2.Rows.Clear();
            _MxAdapter = pFactory.CreateFlexGridAdapter(this.FlexGrid2);
           

            string sColumnHeader = @"年份|季度|指标，年份|季度|指标，
                                             2012|第一季度|供地总量，2012|第一季度|项目数，
                                             2012|第二季度|供地总量，2012|第二季度|项目数，
                                             2012|第三季度|供地总量，2012|第三季度|项目数，
                                             2012|第四季度|供地总量，2012|第四季度|项目数";
            string sColumnDataBind = @"xzq,lx,jd1_gdzl,jd1__xms,jd2_gdzl,jd2_xms,jd3_gdzl,jd3_xms,jd4_gdzl,jd4_xms";
            _MxAdapter.ColumnHeader = sColumnHeader;
            _MxAdapter.ColumnDataBind = sColumnDataBind;
            _MxAdapter.SetColumnHorizontalAlignment(0, System.Windows.HorizontalAlignment.Center);
            _MxAdapter.Style = FlexGridStyle_LR.White;
            _MxAdapter.AutoSelectRow = false;
            _MxAdapter.SeletionBarkground = new SolidColorBrush(Colors.Orange);
            this.FlexGrid2.AllowMerging = AllowMerging.All;          
            _MxAdapter.ItemsSource = GetDatasource2();
        }
        private ObservableCollection<GridViewModel> GetDatasource()
        {
            
            ObservableCollection<GridViewModel> datasource = new ObservableCollection<GridViewModel>();
            datasource.Add(new GridViewModel() 
            {
                nf = "2012",
                jd="第一季度",
                zb = "供地总量",
                cq_zpg=500,
                cq_xycr=100,
                cq_hb=50,
                xsq_zpg = 200,
                xsq_xycr=65,
                xsq_hb = 65,
                yhq_zpg = 1000,
                yhq_xycr = 1525,
                yhq_hb = 500,
                las_zpg = 111,
                las_xycr = 22,
                las_hb = 23,
                tlx_zpg = 90,
                tlx_xycr = 32,
                tlx_hb = 67,
                chax_zpg = 113,
                chax_xycr = 115,
                chax_hb = 66,
                jds_zpg = 124,
                jds_xycr = 32,
                jds_hb = 323,
                fys_zpg = 232,
                fys_xycr = 200,
                fys_hb = 100

                
            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第一季度",
                zb="项目数",
                cq_zpg = 134,
                cq_xycr = 32,
                cq_hb = 632,
                xsq_zpg = 20,
                xsq_xycr = 40,
                xsq_hb = 60,
                yhq_zpg = 71,
                yhq_xycr = 25,
                yhq_hb = 62,
                las_zpg = 26,
                las_xycr = 353,
                las_hb = 37,
                tlx_zpg = 543,
                tlx_xycr = 562,
                tlx_hb = 272,
                chax_zpg = 602,
                chax_xycr = 506,
                chax_hb = 503,
                jds_zpg = 604,
                jds_xycr = 403,
                jds_hb = 203,
                fys_zpg = 503,
                fys_xycr = 103,
                fys_hb = 63


            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第二季度",
                zb = "供地总量",
                cq_zpg =   200,
                cq_xycr =  50,
                cq_hb =    100,
                xsq_zpg =  200,
                xsq_xycr = 44,
                xsq_hb =   32,
                yhq_zpg =  550,
                yhq_xycr = 1000,
                yhq_hb =   1000,
                las_zpg =  99,
                las_xycr = 22,
                las_hb =   35,
                tlx_zpg =  84,
                tlx_xycr = 13,
                tlx_hb =   23,
                chax_zpg = 52,
                chax_xycr = 25,
                chax_hb =  243,
                jds_zpg =  224,
                jds_xycr = 33,
                jds_hb =   25,
                fys_zpg =  613,
                fys_xycr = 33,
                fys_hb =   46

            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第二季度",
                zb = "项目数"
                ,
                cq_zpg = 104,
                cq_xycr = 30,
                cq_hb = 606,
                xsq_zpg = 29,
                xsq_xycr = 46,
                xsq_hb = 66,
                yhq_zpg = 74,
                yhq_xycr = 25,
                yhq_hb = 68,
                las_zpg = 49,
                las_xycr = 450,
                las_hb = 27,
                tlx_zpg = 263,
                tlx_xycr = 25,
                tlx_hb = 27,
                chax_zpg = 28,
                chax_xycr = 28,
                chax_hb = 293,
                jds_zpg = 29,
                jds_xycr = 93,
                jds_hb = 29,
                fys_zpg = 553,
                fys_xycr = 153,
                fys_hb = 25

            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第三季度",
                zb = "供地总量"
                ,
                cq_zpg = 184,
                cq_xycr = 204,
                cq_hb = 93,
                xsq_zpg = 69,
                xsq_xycr = 93,
                xsq_hb = 690,
                yhq_zpg = 650,
                yhq_xycr = 3500,
                yhq_hb = 3500,
                las_zpg = 476,
                las_xycr = 483,
                las_hb = 267,
                tlx_zpg = 26,
                tlx_xycr = 29,
                tlx_hb = 218,
                chax_zpg = 213,
                chax_xycr = 126,
                chax_hb = 213,
                jds_zpg = 21,
                jds_xycr = 113,
                jds_hb = 103,
                fys_zpg = 113,
                fys_xycr = 143,
                fys_hb = 43

            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第三季度",
                zb = "项目数",
                cq_zpg = 124,
                cq_xycr = 34,
                cq_hb = 233,
                xsq_zpg = 23,
                xsq_xycr = 43,
                xsq_hb = 69,
                yhq_zpg = 70,
                yhq_xycr = 24,
                yhq_hb = 67,
                las_zpg = 46,
                las_xycr = 453,
                las_hb = 277,
                tlx_zpg = 23,
                tlx_xycr = 22,
                tlx_hb = 28,
                chax_zpg = 23,
                chax_xycr = 26,
                chax_hb = 233,
                jds_zpg = 24,
                jds_xycr = 413,
                jds_hb = 213,
                fys_zpg = 513,
                fys_xycr = 113,
                fys_hb = 23
                
            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第四季度",
                zb = "供地总量"
                ,
                cq_zpg = 74,
                cq_xycr = 94,
                cq_hb = 363,
                xsq_zpg = 83,
                xsq_xycr = 33,
                xsq_hb = 775,
                yhq_zpg = 1500,
                yhq_xycr = 500,
                yhq_hb = 85,
                las_zpg = 16,
                las_xycr = 43,
                las_hb = 247,
                tlx_zpg = 413,
                tlx_xycr =322,
                tlx_hb = 438,
                chax_zpg = 563,
                chax_xycr = 76,
                chax_hb = 243,
                jds_zpg = 74,
                jds_xycr = 83,
                jds_hb = 28,
                fys_zpg = 58,
                fys_xycr = 153,
                fys_hb = 83

            });
            datasource.Add(new GridViewModel()
            {
                nf = "2012",
                jd = "第四季度",
                zb = "项目数" ,
                cq_zpg = 124,
                cq_xycr = 34,
                cq_hb = 163,
                xsq_zpg = 23,
                xsq_xycr = 43,
                xsq_hb = 69,
                yhq_zpg = 70,
                yhq_xycr = 24,
                yhq_hb = 67,
                las_zpg = 46,
                las_xycr = 453,
                las_hb = 277,
                tlx_zpg = 123,
                tlx_xycr = 232,
                tlx_hb = 218,
                chax_zpg = 23,
                chax_xycr = 26,
                chax_hb = 233,
                jds_zpg = 24,
                jds_xycr = 413,
                jds_hb = 213,
                fys_zpg = 513,
                fys_xycr = 113,
                fys_hb = 23

            });
            return datasource;
        }
        private ObservableCollection<GridViewModel2> GetDatasource2()
        {
            ObservableCollection<GridViewModel2> datasource = new ObservableCollection<GridViewModel2>();
            datasource.Add(new GridViewModel2()
            {
                xzq = "城区",
                lx="招拍挂",
                jd1_gdzl=500,
                jd1__xms=24,
                jd2_gdzl = 200,
                jd2_xms = 26,
                jd3_gdzl = 400,
                jd3_xms = 28,
                jd4_gdzl = 270,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "城区",
                lx = "协议出让",
                jd1_gdzl = 100,
                jd1__xms =32,
                jd2_gdzl = 50,
                jd2_xms = 34,
                jd3_gdzl = 22,
                jd3_xms = 36,
                jd4_gdzl = 34,
                jd4_xms = 38
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "城区",
                lx = "划拨",
                jd1_gdzl = 50,
                jd1__xms = 24,
                jd2_gdzl = 10,
                jd2_xms = 26,
                jd3_gdzl = 12,
                jd3_xms = 28,
                jd4_gdzl = 21,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "萧山区",
                lx = "招拍挂",
                jd1_gdzl = 200,
                jd1__xms = 42,
                jd2_gdzl = 200,
                jd2_xms = 44,
                jd3_gdzl = 100,
                jd3_xms = 46,
                jd4_gdzl = 90,
                jd4_xms = 48
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "萧山区",
                lx = "协议出让",
                jd1_gdzl = 65,
                jd1__xms = 24,
                jd2_gdzl = 44,
                jd2_xms = 26,
                jd3_gdzl = 32,
                jd3_xms = 28,
                jd4_gdzl = 12,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "萧山区",
                lx = "划拨",
                jd1_gdzl = 65,
                jd1__xms = 52,
                jd2_gdzl = 32,
                jd2_xms = 54,
                jd3_gdzl = 62,
                jd3_xms = 56,
                jd4_gdzl = 16,
                jd4_xms = 58
            });
            //
            datasource.Add(new GridViewModel2()
            {
                xzq = "余杭区",
                lx = "招拍挂",
                jd1_gdzl = 1000,
                jd1__xms = 24,
                jd2_gdzl = 550,
                jd2_xms = 26,
                jd3_gdzl = 650,
                jd3_xms = 28,
                jd4_gdzl = 775,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "余杭区",
                lx = "协议出让",
                jd1_gdzl =1525,
                jd1__xms = 62,
                jd2_gdzl = 1000,
                jd2_xms = 64,
                jd3_gdzl = 3500,
                jd3_xms = 66,
                jd4_gdzl = 1500,
                jd4_xms = 68
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "余杭区",
                lx = "划拨",
                jd1_gdzl = 500,
                jd1__xms = 24,
                jd2_gdzl = 1000,
                jd2_xms = 26,
                jd3_gdzl = 3500,
                jd3_xms = 28,
                jd4_gdzl = 500,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "临安市",
                lx = "招拍挂",
                jd1_gdzl = 71,
                jd1__xms = 72,
                jd2_gdzl = 73,
                jd2_xms = 74,
                jd3_gdzl = 75,
                jd3_xms = 76,
                jd4_gdzl = 77,
                jd4_xms = 78
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "临安市",
                lx = "协议出让",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "临安市",
                lx = "划拨",
                jd1_gdzl = 81,
                jd1__xms = 82,
                jd2_gdzl =83,
                jd2_xms = 84,
                jd3_gdzl =85,
                jd3_xms = 86,
                jd4_gdzl = 87,
                jd4_xms = 88
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "桐庐县",
                lx = "招拍挂",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "桐庐县",
                lx = "协议出让",
                jd1_gdzl =91,
                jd1__xms = 92,
                jd2_gdzl = 93,
                jd2_xms = 94,
                jd3_gdzl = 95,
                jd3_xms = 96,
                jd4_gdzl = 97,
                jd4_xms = 98
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "桐庐县",
                lx = "划拨",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "淳安县",
                lx = "招拍挂",
                jd1_gdzl = 11,
                jd1__xms = 12,
                jd2_gdzl = 124,
                jd2_xms = 15,
                jd3_gdzl =16,
                jd3_xms =17,
                jd4_gdzl = 18,
                jd4_xms = 19
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "淳安县",
                lx = "协议出让",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "淳安县",
                lx = "划拨",
                jd1_gdzl = 123,
                jd1__xms = 124,
                jd2_gdzl = 125,
                jd2_xms = 126,
                jd3_gdzl = 127,
                jd3_xms = 128,
                jd4_gdzl = 129,
                jd4_xms = 130
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "建德市",
                lx = "招拍挂",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "建德市",
                lx = "协议出让",
                jd1_gdzl = 223,
                jd1__xms = 224,
                jd2_gdzl = 225,
                jd2_xms = 226,
                jd3_gdzl = 227,
                jd3_xms = 228,
                jd4_gdzl = 229,
                jd4_xms = 230
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "建德市",
                lx = "划拨",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "富阳市",
                lx = "招拍挂",
                jd1_gdzl = 323,
                jd1__xms = 324,
                jd2_gdzl = 325,
                jd2_xms = 326,
                jd3_gdzl =327,
                jd3_xms = 328,
                jd4_gdzl = 329,
                jd4_xms = 330
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "富阳市",
                lx = "协议出让",
                jd1_gdzl = 23,
                jd1__xms = 24,
                jd2_gdzl = 25,
                jd2_xms = 26,
                jd3_gdzl = 27,
                jd3_xms = 28,
                jd4_gdzl = 29,
                jd4_xms = 30
            });
            datasource.Add(new GridViewModel2()
            {
                xzq = "富阳市",
                lx = "划拨",
                jd1_gdzl = 423,
                jd1__xms = 424,
                jd2_gdzl = 425,
                jd2_xms = 426,
                jd3_gdzl = 427,
                jd3_xms = 428,
                jd4_gdzl =429,
                jd4_xms =430
            });
            return datasource;
        }

        private void FlexGrid1_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            EventAggregatorRepository.EventAggregator
                  .GetEvent<StatisticNaviEvent>()
                  .Publish(new StatisticNavi(){ State = 2});   
        }
    }

    public class GridViewModel
    {
        public string nf { get; set; }
        public string jd  { get; set; }
        public string zb { get; set; }

        //城区
        public double cq_zpg { get; set; }
        public double cq_xycr { get; set; }
        public double cq_hb { get; set; }
        //萧山区
        public double xsq_zpg { get; set; }
        public double xsq_xycr { get; set; }
        public double xsq_hb { get; set; }
        //余杭区
        public double yhq_zpg { get; set; }
        public double yhq_xycr { get; set; }
        public double yhq_hb { get; set; }
        //临安市
        public double las_zpg { get; set; }
        public double las_xycr { get; set; }
        public double las_hb { get; set; }
        //桐庐县
        public double tlx_zpg { get; set; }
        public double tlx_xycr { get; set; }
        public double tlx_hb { get; set; }
        //淳安县
        public double chax_zpg { get; set; }
        public double chax_xycr { get; set; }
        public double chax_hb { get; set; }
        //建德市
        public double jds_zpg { get; set; }
        public double jds_xycr { get; set; }
        public double jds_hb { get; set; }
        //富阳市
        public double fys_zpg { get; set; }
        public double fys_xycr { get; set; }
        public double fys_hb { get; set; }
    }
    public class GridViewModel2
    { 
        public string xzq { get; set; }
        public string lx { get; set; }
        public double jd1_gdzl { get; set; }
        public double jd1__xms { get; set; }
        public double jd2_gdzl { get; set; }
        public double jd2_xms { get; set; }
        public double jd3_gdzl { get; set; }
        public double jd3_xms { get; set; }
        public double jd4_gdzl { get; set; }
        public double jd4_xms { get; set; }
    }
}
